<?php
/////////////////////////////////////////////////////////////////////////////
// 这个文件是 网城创想多用户商城 项目的一部分
//
// Copyright (c) 2007 - 2008 www.shopnc.net 
//
// 要查看完整的版权信息和许可信息，请查看源代码中附带的 COPYRIGHT 文件，
// 或者访问 http://www.shopnc.net/ 获得详细信息。
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : own_productcategory.php   FILE_PATH : D:\webroot\mulitishop\member\own_productcategory.php
 * ....商家管理宝贝分类
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author 网城创想多用户商城开发团队 php_netproject@yahoo.com.cn
 * @package 
 * @subpackage 
 * @version Tue Sep 11 12:42:43 CST 2007
 */

require_once("../global.inc.php");

class OwnShopProduct extends CommonFrameWork{
	/**
	 * 商铺宝贝分类对象
	 *
	 * @var obj
	 */
	var $obj_product;
	/**
	 * 商铺宝贝分类对象
	 *
	 * @var obj
	 */
	var $obj_productcategory;
	/**
	 * 验证对象
	 *
	 * @var obj
	 */
	var $objvalidate;
	
	function main(){
		$this->memberMenuModule();
		/**
		 * 创建商品对象
		 */
		if (!is_object($this->obj_productcategory)){
			require_once("product.class.php");
			$this->obj_product = new ProductClass();
		}
		/**
		 * 创建商铺宝贝分类对象
		 */
		if (!is_object($this->obj_productcategory)){
			require_once("shopproductcategory.class.php");
			$this->obj_productcategory = new ShopProductCategoryClass();
		}
		/**
		 * 创建验证对象
		 */
		if (!is_object($this->objvalidate)){
			require_once("commonvalidate.class.php");
			$this->objvalidate = new CommonValidate();
		}
		
		/**
		 * 设置模板路径
		 */
		$this->setsubtemplates("member");
		
		/**
		 * 语言包
		 */
		$this->getlang("shop");
		
		$this->_input['hideShopId'] = $_SESSION["s_shop"]['id'];
		
		/**
		 * 根据参数调用相应的方法
		 */
		switch ($this->_input['action']){
			case "list":
				$this->shopMenuModule();
				$this->_listproduct();
				break;
			case "move":
				$this->_moveproduct();
				break;
			case "recommended_list":
				$this->shopMenuModule();
				$this->_listrecommendedproduct();
				break;
			case "recommended":
				$recommended = "1";
				$this->_updateproductrecommended($recommended);
				break;
			case "cancel_recommended":
				$recommended = "0";
				$this->_updateproductrecommended($recommended);
				break;
			default:
				$this->shopMenuModule();
				$this->_listproduct();
		}
		
	}
	
	/**
	 * 商铺宝贝分类
	 *
	 */
	function _listproduct(){
		/**
		 * 得到店铺宝贝分类
		 */
		$product_category = $this->obj_productcategory->getCategory($_SESSION['s_shop']['id'],$page);
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();

		/**
		 * 取得查询参数
		 */
		$obj_condition[key] = $this->_input['keyword'];
		$obj_condition[keygenre] = $this->_input['searchtype'];
		$obj_condition[p_class_id] = $this->_input['classid'];
		$obj_condition[member] = $_SESSION['s_login']['id'];
		
		/**
		 * 实例化商品订单类
		 */
		if (!is_object($this->obj_product_order)){
			require_once("order.class.php");
			$this->obj_product_order = new ProductOrderClass();
		}
		/**
		 * 更新到期团购商品订单状态
		 */
		$group_product_order_tobe_end_array = $this->obj_product_order->updateProductOrderInCondition();
		/**
		 * 更新到期商品状态
		 */
		$product_tobe_end_array = $this->obj_product->updateProductInCondition();
		/**
		 * 取得产品列表
		 */
		$obj_condition[state] = $state;
		$obj_page->pagebarnum(10);
		$product_array = $this->obj_product->getProductList($obj_condition, $obj_page);
		$page_list = $obj_page->show(1);
		/**
		 * 输出到页面模板
		 */
		for($i=0;$i<count($product_array);$i++){
			$left_time = $product_array[$i]['p_end_time'] - time();
			$product_array[$i]['left_days'] = intval($left_time / (24*60*60));
			$product_array[$i]['left_hours'] = intval(($left_time % (24*60*60)) / (60*60));
			$product_array[$i]['left_minutes'] = intval((($left_time % (60*60))) / 60);
		}
		foreach ($product_category as $value){
			$shop_product_cate[$value[class_id]] = $value[class_name];
		}
		$this->output("page_list", $page_list);
		$this->output("shop_product_array", $product_array);
		$this->output("shop_product_category_array", Common::showForm_Select("shoppcid","","",$shop_product_cate,""));    //输出店铺宝贝分类
		$this->showpage("own_shopproduct.list");   //显示页面
	}
	
	/**
	 * 保存商铺宝贝分类
	 *
	 */
	function _moveproduct(){
		/**
		 * 检验输入信息
		 */
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["chboxPid"],"require"=>"true","message"=>$this->_lang['errShopProductNoSelected']));
		/**
		 * 检验的错误信息
		 */
		$error = $this->objvalidate->validate();
		/**
		 * 保存到数据库中
		 */
		if($error != ""){
			$this->redirectPath("error","",$error);
		}else{
			$this->obj_product->updateShopProductCategory($this->_input); //把信息放入数据库中
			$this->redirectPath("succ","/member/own_shopproduct.php?action=list&classid=0","商品已经成功移动到所选宝贝分类！");
		}
		
	}
	
	/**
	 * 商铺宝贝推荐列表
	 *
	 */
	function _listrecommendedproduct(){
		/**
		 * 得到店铺宝贝分类
		 */
		$product_category = $this->obj_productcategory->getCategory($_SESSION['s_shop']['id'],$page);
		/**
		 * 初始化分页类
		 */
		require_once("commonpage.class.php");
		$obj_page = new CommonPage();

		/**
		 * 取得查询参数
		 */
		$obj_condition[key] = $this->_input['keyword'];
		$obj_condition[keygenre] = $this->_input['searchtype'];
		$obj_condition[p_class_id] = $this->_input['classid'];
		$obj_condition[member] = $_SESSION['s_login']['id'];
		
		/**
		 * 实例化商品订单类
		 */
		if (!is_object($this->obj_product_order)){
			require_once("order.class.php");
			$this->obj_product_order = new ProductOrderClass();
		}
		/**
		 * 更新到期团购商品订单状态
		 */
		$group_product_order_tobe_end_array = $this->obj_product_order->updateProductOrderInCondition();
		/**
		 * 更新到期商品状态
		 */
		$product_tobe_end_array = $this->obj_product->updateProductInCondition();
		/**
		 * 取得产品列表
		 */
		$obj_condition[state] = $state;
		$obj_page->pagebarnum(10);
		$product_array = $this->obj_product->getProductList($obj_condition, $obj_page);
		$page_list = $obj_page->show(1);
		/**
		 * 输出到页面模板
		 */
		$j = 0;
		for($i=0;$i<count($product_array);$i++){
			$left_time = $product_array[$i]['p_end_time'] - time();
			$product_array[$i]['left_days'] = intval($left_time / (24*60*60));
			$product_array[$i]['left_hours'] = intval(($left_time % (24*60*60)) / (60*60));
			$product_array[$i]['left_minutes'] = intval((($left_time % (60*60))) / 60);
			
		}
		
		$obj_recommended_condition['member'] = $this->_input['userid'];
		$obj_recommended_condition['store_recommended'] = 1;
		$product_store_recommended = $this->obj_product->getProductList($obj_recommended_condition, $obj_recommended_page);
		
		foreach ($product_category as $value){
			$shop_product_cate[$value[class_id]] = $value[class_name];
		}
		$this->output("page_list", $page_list);
		$this->output("shop_product_array", $product_array);
		$this->output("shop_recommended_product_array", $product_store_recommended);
		$this->output("shop_product_category_array", Common::showForm_Select("shoppcid","","",$shop_product_cate,""));    //输出店铺宝贝分类
		$this->showpage("own_shopproduct.recommended");   //显示页面
	}
	
	/**
	 * 更新商品店铺推荐状态
	 *
	 * @param unknown_type $recommended
	 */
	function _updateproductrecommended($recommended){
		$this->objvalidate->validateparam = array(
		array("input"=>$this->_input["chboxPid"],"require"=>"true","message"=>$this->_lang['errProductCodeEmpty']));
		$error = $this->objvalidate->validate();
		if($error != ""){
			echo $error;
		}else{
			$this->_input['recommended'] = $recommended;
			$result = $this->obj_product->updateProductShopRecommended($this->_input);
			if($recommended == "1"){
				$info = "宝贝已成功推荐！";
			}else{
				$info = "宝贝已取消推荐！";
			}
			$this->redirectPath("succ","/member/own_shopproduct.php?action=recommended_list", $info);
		}
	}
}

$shop_product_manage = new OwnShopProduct();
$shop_product_manage->main();
unset($shop_product_manage);
?>